import * as echarts from 'echarts'


// 注册中国地图数据
echarts.registerMap('china', chinaJson)

// 初始化ECharts实例
export const initECharts = (el: HTMLElement) => {
  const chart = echarts.init(el)
  return chart
}

// 设置地图配置项
export const getMapOption = (title: string) => {
  return {
    title: {
      text: title,
      left: 'center'
    },
    tooltip: {
      trigger: 'item',
      formatter: '{b}'
    },
    visualMap: {
      min: 0,
      max: 100,
      left: 'left',
      top: 'bottom',
      text: ['高', '低'],
      calculable: true,
      inRange: {
        color: ['#e0f3f8', '#045a8d']
      }
    },
    series: [
      {
        name: '中国',
        type: 'map',
        map: 'china',
        roam: true,
        emphasis: {
          label: {
            show: true
          }
        },
        data: [
          { name: '北京', value: 100 },
          { name: '天津', value: 90 },
          { name: '上海', value: 95 },
          { name: '重庆', value: 85 },
          { name: '河北', value: 80 },
          { name: '山西', value: 75 },
          { name: '辽宁', value: 70 },
          { name: '吉林', value: 65 },
          { name: '黑龙江', value: 60 },
          { name: '江苏', value: 85 },
          { name: '浙江', value: 90 },
          { name: '安徽', value: 75 },
          { name: '福建', value: 80 },
          { name: '江西', value: 70 },
          { name: '山东', value: 85 },
          { name: '河南', value: 80 },
          { name: '湖北', value: 75 },
          { name: '湖南', value: 80 },
          { name: '广东', value: 95 },
          { name: '海南', value: 70 },
          { name: '四川', value: 85 },
          { name: '贵州', value: 70 },
          { name: '云南', value: 75 },
          { name: '陕西', value: 80 },
          { name: '甘肃', value: 65 },
          { name: '青海', value: 60 },
          { name: '台湾', value: 85 },
          { name: '内蒙古', value: 70 },
          { name: '广西', value: 75 },
          { name: '西藏', value: 60 },
          { name: '宁夏', value: 65 },
          { name: '新疆', value: 70 },
          { name: '香港', value: 90 },
          { name: '澳门', value: 85 }
        ]
      }
    ]
  }
}

// 设置省份地图配置项
export const getProvinceOption = (provinceName: string, data: any[]) => {
  return {
    title: {
      text: `${provinceName}地方特色菜系`,
      left: 'center'
    },
    tooltip: {
      trigger: 'item',
      formatter: '{b}'
    },
    visualMap: {
      min: 0,
      max: 100,
      left: 'left',
      top: 'bottom',
      text: ['高', '低'],
      calculable: true,
      inRange: {
        color: ['#e0f3f8', '#045a8d']
      }
    },
    series: [
      {
        name: provinceName,
        type: 'map',
        map: provinceName,
        roam: true,
        emphasis: {
          label: {
            show: true
          }
        },
        data: data
      }
    ]
  }
} 